namespace MsForgeReboot.Services.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class UsersAndRoles : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Password = c.String(maxLength: 100),
                        Username = c.String(maxLength: 100),
                    })
                .PrimaryKey(t => t.Id);
            
            //CreateTable(
            //    "dbo.Roles",
            //    c => new
            //        {
            //            Id = c.Int(nullable: false, identity: true),
            //            Name = c.String(maxLength: 100),
            //            Description = c.String(maxLength: 500),
            //        })
            //    .PrimaryKey(t => t.Id);
            
            //CreateTable(
            //    "dbo.RoleUsers",
            //    c => new
            //        {
            //            Role_Id = c.Int(nullable: false),
            //            User_Id = c.Int(nullable: false),
            //        })
            //    .PrimaryKey(t => new { t.Role_Id, t.User_Id })
            //    .ForeignKey("dbo.Roles", t => t.Role_Id, cascadeDelete: true)
            //    .ForeignKey("dbo.Users", t => t.User_Id, cascadeDelete: true)
            //    .Index(t => t.Role_Id)
            //    .Index(t => t.User_Id);
            
            AddColumn("dbo.BlogPosts", "Author_Id", c => c.Int());
            AddColumn("dbo.Pages", "Author_Id", c => c.Int());
            AddForeignKey("dbo.BlogPosts", "Author_Id", "dbo.Users", "Id");
            AddForeignKey("dbo.Pages", "Author_Id", "dbo.Users", "Id");
            CreateIndex("dbo.BlogPosts", "Author_Id");
            CreateIndex("dbo.Pages", "Author_Id");
            DropColumn("dbo.BlogPosts", "Author");
        }
        
        public override void Down()
        {
            AddColumn("dbo.BlogPosts", "Author", c => c.Int(nullable: false));
            //DropIndex("dbo.RoleUsers", new[] { "User_Id" });
            //DropIndex("dbo.RoleUsers", new[] { "Role_Id" });
            DropIndex("dbo.Pages", new[] { "Author_Id" });
            DropIndex("dbo.BlogPosts", new[] { "Author_Id" });
            //DropForeignKey("dbo.RoleUsers", "User_Id", "dbo.Users");
            //DropForeignKey("dbo.RoleUsers", "Role_Id", "dbo.Roles");
            DropForeignKey("dbo.Pages", "Author_Id", "dbo.Users");
            DropForeignKey("dbo.BlogPosts", "Author_Id", "dbo.Users");
            DropColumn("dbo.Pages", "Author_Id");
            DropColumn("dbo.BlogPosts", "Author_Id");
            //DropTable("dbo.RoleUsers");
            //DropTable("dbo.Roles");
            DropTable("dbo.Users");
        }
    }
}
